package com.hbnu.test.www.net;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

public class UdpSend2 {
    public static void main(String[] args) {
        try(DatagramSocket datagramSocket = new DatagramSocket(6666)){
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
            String line = null;
            while((line = bufferedReader.readLine())!=null){
                if("bye".equalsIgnoreCase(line)){
                    break;
                }
            byte[] bytes = line.getBytes();
                DatagramPacket datagramPacket = new DatagramPacket(bytes, bytes.length, InetAddress.getByName("127.0.0.1"), 8888);
                datagramSocket.send(datagramPacket);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
